package com.tengju.data.infrastructure.repository.clickhouse.crm;

import com.tengju.data.domain.model.clickhouse.CrmSecPullingAnalysisRepository;
import com.tengju.data.domain.model.clickhouse.UserPulling;
import com.tengju.data.domain.model.user.StarLevelEnum;
import com.tengju.data.domain.shared.Quarter;
import com.tengju.data.infrastructure.persistence.mybatis.dataobject.UserPullingVO;
import com.tengju.data.infrastructure.persistence.mybatis.mapper.clickhouse.crm.CRMSecAnalysisMapper;
import com.tengju.data.infrastructure.repository.clickhouse.convert.CrmSecAnalysisConvert;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author chenhang
 * @Date 2021/3/19
 */
@Repository
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class CrmSecPullingAnalysisRepositoryImpl implements CrmSecPullingAnalysisRepository {

    private final CRMSecAnalysisMapper crmSecAnalysisMapper;

    @Override
    public List<UserPulling> listSecBlackPulling(Long clubId, Quarter quarter, StarLevelEnum starLevel) {
        List<UserPullingVO> userPullingVOList = crmSecAnalysisMapper.listSecPulling(clubId,quarter.getStartDate(),starLevel.getCode());
        if (CollectionUtils.isEmpty(userPullingVOList)) {
            return Collections.emptyList();
        }
        return userPullingVOList.stream()
                .map(CrmSecAnalysisConvert::toUserPullingModel)
                .collect(Collectors.toList());
    }
}
